<template>
	<u-popup v-model="showPop" mode="bottom" border-radius="14" :closeable="true" @close="onClose"
		:safe-area-inset-bottom="true">
		<view class="bg-white select-coupon-contain">
			<view class="main-container">
				<view class="enble-title">可用优惠券</view>
				<u-radio-group v-model="selected">
					<view class="item enable" :class="selected === item.id ? 'active' : ''" @tap="onClickItem(item)" v-for="(item, index) in dataList" :key="index">
						<view class="left-box">
							<view class="title">{{item.title}}</view>
							<view class="desc">{{item.desc}}</view>
							<view class="date">{{item.date}}</view>
						</view>
						<view class="right-box">
							<view class="val-box">
								<price-format
								  :price="item.price"
								  :first-size="56"
								  :subscript-size="24"
								  :weight="500"
								  color="#FF2C3C"
								></price-format>
								<view class="desc">{{item.rule}}</view>
							</view>
							<view class="radio-box">
								<u-radio :name="item.id"></u-radio>
							</view>
						</view>
					</view>
				</u-radio-group>
				
				<view class="disabled-title">不可用</view>
				<view class="item disabled">
					<view class="left-box">
						<view class="title">零售商品满减券</view>
						<view class="desc">零售商城可用</view>
						<view class="date">2024.01.24-2024.01.24</view>
					</view>
					<view class="right-box">
						<view class="val-box">
							<price-format
							  :price="50"
							  :first-size="56"
							  :subscript-size="24"
							  :weight="500"
							  color="#CCCCCC"
							></price-format>
							<view class="desc">满500可用</view>
						</view>
					</view>
				</view>
			</view>
			<view class="footer-container">
				<view class="btn" :class="selected ? '' : 'disabled'" @tap="onClickConfirmBtn">确 定</view>
			</view>
		</view>
	</u-popup>
</template>

<script>
	export default {
		data() {
			return {
				showPop: false,
				selected: '',
				dataList: []
			};
		},

		props: {
			show: {
				type: Boolean
			},
			
		},


		watch: {
			show(val) {
				this.showPop = val
				this.selected = ''
				
				if(val){
					this.handleQueryList()
				}
			}
		},
		methods: {

			onClose() {
				this.$emit('close')
			},
			
			
			onClickItem(item){
				this.selected = item.id
			},
			
			onClickConfirmBtn(){
				if(this.selected){
					this.$emit('confirm', this.selected)
					this.onClose()
				}
			},
			
			handleQueryList(){
				setTimeout(()=>{
					this.dataList = [
						{
							title: "零售商品满减券",
							desc: '零售商品可用',
							date: '2024.01.24-2024.01.24',
							price: '50',
							rule: '满500可用',
							id: '1'
						},
						{
							title: "零售商品满减券",
							desc: '零售商品可用',
							date: '2024.01.24-2024.01.24',
							price: '50',
							rule: '满500可用',
							id: '2'
						},
					]
				},1000)
			}


		}
	};
</script>
<style lang="scss" scoped>
	.select-coupon-contain {
		border-radius: 10rpx 10rpx 0 0;
		overflow: hidden;
		position: relative;
		padding-top: 50rpx;


		.enble-title {
			font-size: 36rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 600;
			color: #333333;
			margin-bottom: 20rpx;
		}

		.disabled-title {
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #999999;
			margin-bottom: 20rpx;
		}

		.main-container {
			height: 750rpx;
			overflow: auto;
			padding: 0 20rpx;
			
			.item{
				height: 220rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-radius: 20rpx;
				border: 2rpx solid;
				margin-bottom: 20rpx;
				padding: 0 20rpx;
				.left-box{
					flex: 1;
					margin-right: 30rpx;
					overflow: hidden;
					.title{
						font-size: 34rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 600;
						line-height: 40rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
					
					.desc{
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						line-height: 32rpx;
						margin-top: 20rpx;
					}
					.date{
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						line-height: 32rpx;
					}
				}
				
				.right-box{
					display: flex;
					align-items: center;
					.val-box{
						display: flex;
						flex-direction: column;
						align-items: flex-end;
						.desc{
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							line-height: 24rpx;
						}
					}
					.radio-box{
						margin-left: 20rpx;
						margin-right: -20rpx;
					}
				}
			}
			.item.enable{
				border-color: #E9F4FF;
				.left-box{
					.title{
						color: #333333;
					}
					.desc,.date{
						color: #666666;
					}
				}
				.right-box{
					.val-box{
						.desc{
							color: #FF2C3C;
						}
					}
				}
			}
			.item.active{
				border-color: #1E8AF4;
				background-color: #E9F4FF;
				
			}
			.item.disabled{
				border-color: #cccccc;
				.left-box{
					.title{
						color: #cccccc;
					}
					.desc,.date{
						color: #cccccc;
					}
				}
				.right-box{
					.val-box{
						.desc{
							color: #cccccc;
						}
					}
				}
			}
		}


		.footer-container {
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 20rpx 0 50rpx;
			background: #FFFFFF;

			.btn {
				width: 694rpx;
				height: 96rpx;
				background: #1E8AF4;
				border-radius: 60rpx;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			.disabled{
				background: #bdbdbd;
			}
		}
	}
</style>